<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>现代CSS模块化方案</title>
    <style>
        /* 基础变量和重置样式 */
        :root {
            --primary: #007bff;
            --secondary: #6c757d;
            --success: #28a745;
            --danger: #dc3545;
            --light: #f8f9fa;
            --dark: #343a40;
            --spacing: 1rem;
            --border-radius: 4px;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            padding: 2rem;
            color: var(--dark);
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 var(--spacing);
        }

        /* BEM命名规范示例 */
        .card {
            background: var(--light);
            border-radius: var(--border-radius);
            padding: var(--spacing);
            margin-bottom: var(--spacing);
        }

        .card--primary {
            background: var(--primary);
            color: white;
        }

        .card--secondary {
            background: var(--secondary);
            color: white;
        }

        .card__header {
            border-bottom: 1px solid rgba(0,0,0,0.1);
            padding-bottom: var(--spacing);
            margin-bottom: var(--spacing);
        }

        .card__title {
            margin: 0;
            font-size: 1.25rem;
        }

        .card__content {
            margin-bottom: var(--spacing);
        }

        .card__footer {
            border-top: 1px solid rgba(0,0,0,0.1);
            padding-top: var(--spacing);
        }

        /* OOCSS示例 */
        .btn {
            display: inline-block;
            padding: 0.5rem 1rem;
            border: none;
            border-radius: var(--border-radius);
            cursor: pointer;
            text-decoration: none;
            text-align: center;
            transition: all 0.3s ease;
        }

        .btn--primary {
            background: var(--primary);
            color: white;
        }

        .btn--secondary {
            background: var(--secondary);
            color: white;
        }

        .btn--large {
            padding: 0.75rem 1.5rem;
            font-size: 1.1rem;
        }

        .btn--small {
            padding: 0.25rem 0.5rem;
            font-size: 0.875rem;
        }

        /* Utility Classes */
        .mt-1 { margin-top: calc(var(--spacing) * 0.25); }
        .mt-2 { margin-top: calc(var(--spacing) * 0.5); }
        .mt-3 { margin-top: var(--spacing); }
        .mt-4 { margin-top: calc(var(--spacing) * 1.5); }
        .mt-5 { margin-top: calc(var(--spacing) * 3); }

        .mb-1 { margin-bottom: calc(var(--spacing) * 0.25); }
        .mb-2 { margin-bottom: calc(var(--spacing) * 0.5); }
        .mb-3 { margin-bottom: var(--spacing); }
        .mb-4 { margin-bottom: calc(var(--spacing) * 1.5); }
        .mb-5 { margin-bottom: calc(var(--spacing) * 3); }

        .text-center { text-align: center; }
        .text-right { text-align: right; }
        .text-left { text-align: left; }

        .d-flex { display: flex; }
        .justify-content-between { justify-content: space-between; }
        .align-items-center { align-items: center; }

        /* 主题系统 */
        [data-theme="dark"] {
            --bg-color: var(--dark);
            --text-color: var(--light);
            background-color: var(--bg-color);
            color: var(--text-color);
        }

        [data-theme="dark"] .card {
            background: #2b3035;
            color: var(--light);
        }

        /* 响应式设计 */
        @media (max-width: 768px) {
            .card {
                margin: var(--spacing);
            }

            .d-flex {
                flex-direction: column;
            }

            .btn {
                width: 100%;
                margin-bottom: 0.5rem;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="mb-4">现代CSS模块化方案</h1>
        
        <div class="mb-3">
            <button class="btn btn--primary" onclick="toggleTheme()">切换主题</button>
        </div>

        <section class="mb-5">
            <h2 class="mb-3">BEM命名规范示例</h2>
            <div class="card card--primary mb-3">
                <div class="card__header">
                    <h3 class="card__title">主要卡片</h3>
                </div>
                <div class="card__content">
                    <p>这是一个使用BEM命名规范的卡片组件示例。</p>
                </div>
                <div class="card__footer">
                    <button class="btn btn--secondary">了解更多</button>
                </div>
            </div>
        </section>

        <section class="mb-5">
            <h2 class="mb-3">OOCSS示例</h2>
            <div class="d-flex justify-content-between mb-3">
                <button class="btn btn--primary btn--small">小按钮</button>
                <button class="btn btn--primary">默认按钮</button>
                <button class="btn btn--primary btn--large">大按钮</button>
            </div>
        </section>

        <section class="mb-5">
            <h2 class="mb-3">Utility Classes示例</h2>
            <div class="card mb-3">
                <div class="text-center mb-3">
                    <h3>文本居中</h3>
                </div>
                <div class="text-right mb-3">
                    <p>文本右对齐</p>
                </div>
                <div class="text-left">
                    <p>文本左对齐</p>
                </div>
            </div>
        </section>

        <section>
            <h2 class="mb-3">响应式设计</h2>
            <div class="d-flex justify-content-between">
                <div class="card" style="flex: 1; margin-right: 1rem;">
                    <h3>卡片1</h3>
                    <p>在移动设备上会变成垂直布局</p>
                </div>
                <div class="card" style="flex: 1;">
                    <h3>卡片2</h3>
                    <p>在移动设备上会变成垂直布局</p>
                </div>
            </div>
        </section>
    </div>

    <script>
        function toggleTheme() {
            const body = document.body;
            const currentTheme = body.getAttribute('data-theme');
            body.setAttribute('data-theme', currentTheme === 'dark' ? 'light' : 'dark');
        }
    </script>
</body>
</html>
